package com.wzdigit.wms.wms.controller.inv.count;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.domain.basic.Sku;
import com.wzdigit.wms.basic.domain.basic.SkuCate;
import com.wzdigit.wms.basic.domain.inventory.Lotno;
import com.wzdigit.wms.wms.client.request.inv.count.dto.ReTaskDto;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.inv.count.InvReCountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

/**
 * 复盘BS
 * Created by zyf on 2021/10/16 15:13
 */
@RestController
@Api(tags = "复盘BS")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class InvReCountController {
    public static final String REQUEST_MODEL = "/reCount";

    @Autowired
    private InvReCountService reCountService;

    @ApiOperation(value = "复盘批次号下拉框（分页）", notes = "复盘批次号下拉框（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/reLot", method = RequestMethod.GET)
    public PagerInfo<List<Lotno>> searchReLot(
            BigDecimal heaerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reCountService.searchReLot(heaerId,pager);
    }

    @ApiOperation(value = "复盘物料分类下拉框（分页）", notes = "复盘物料分类下拉框（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/reCate", method = RequestMethod.GET)
    public PagerInfo<List<SkuCate>> searchReCate(
            BigDecimal heaerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reCountService.searchReCate(heaerId,pager);
    }

    @ApiOperation(value = "复盘物料编码下拉框（分页）", notes = "复盘物料编码下拉框（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/reSku", method = RequestMethod.GET)
    public PagerInfo<List<Sku>> searchReSku(
            BigDecimal heaerId, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        return reCountService.searchReSku(heaerId,pager);
    }

    @ApiOperation(value = "生成复盘任务", notes = "生成复盘任务")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/reTask", method = RequestMethod.POST)
    public Result<String> createReCountTask(
            @RequestBody ReTaskDto taskDto,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            return reCountService.createReTask(taskDto,servletRequest);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

}
